package com.quark.web.ui.field;

import com.quark.data.type.QuarkVariable;
import com.quark.framework.ormapping.QuarkOrmEntity;
import com.quark.framework.utility.QuarkLog;
import com.quark.framework.utility.QuarkUtilHtmlEscape;
import com.quark.web.ui.base.QuarkUiElementBase;
import com.quark.web.ui.base.QuarkUiInputElement;
import com.quark.web.ui.base.QuarkUiSetting;

public class QuarkUiNormalTextField extends QuarkUiFieldBase {
	
	protected QuarkUiInputElement element = null;
	public QuarkUiNormalTextField(String fieldName)
	{
		super(fieldName, new QuarkUiInputElement(fieldName, fieldName, QuarkUiSetting.TEXT_INPUT_CLASS, ""));
		element = (QuarkUiInputElement) super.elementBase;
	}

	public String createField()
	{
		return element.createElement();
	}
	
	public void clearField()
	{
		element.clearValue();
	}
	
	public boolean fillFieldWith(Object param)
	{
		if(param != null)
		{
			element.setValue(param.toString());
		}
		else
		{
			QuarkLog.logMessage(getClass().getName(), "can't fill field with null");
			element.clearValue();
		}
		return true;
	}
	
	public Object processSumbitData(Object rawData)
	{
		if(!rawData.getClass().equals(String.class))
		{
			QuarkLog.logError(getClass().getName(), String.class.getName() + " expected, not " + rawData.getClass().getName());
			return null;
		}
		
		return new QuarkVariable(rawData, String.class);
	}
	
	public QuarkUiElementBase getElement() 
	{
		return element;
	}
}
